<?php
/* 类型控制器
* @Author: Jerry-chen
* @Date:   2014-07-07 14:30:27
* @Last Modified time: 2014-07-17 14:37:38
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/
class TypeControl extends CommonControl
{
	public $model;
	public $attrmodel;

	/**
	 * 自动运行
	 */
	public function __auto()
	{
		$this->model = K('Type');
		$this->attrmodel = K('Attr');
	}
	public function index()
	{
		$typeDate = $this->model->get_all();
		//根据查找出来的类型ID，找出相关的属性值
		// 分配变量
		$this->assign('typeDate',$typeDate);

		$this->display();
	}
	/**
	 * [add_type 增加类型]
	 */
	public function add_type()
	{
		if(IS_POST)
		{
			$this->model->add_type();
			$this->success('添加成功');
		}
		
		$this->display();
	}
	/**
	 * [attr_list 属性列表]
	 * @return [type] [description]
	 */
	public function attr_list()
	{
		//根据类型ID，查找出相关的属性值
		$typeid = Q('get.typeid'); 
		$where  = array('typeid'=>$typeid);
		$attrData = $this->attrmodel->get_all($where);
		$this->assign('attrData',$attrData);
		$this->display();
	}
	/**
	 * [add_attr 添加属性]
	 */
	public function add_attr()
	{
		$typeid = Q('get.typeid','','intval');
		//查出当前type对应的ID值，方便名称
		$typeDate = $this->model->get_one($typeid);
		//分配变量
		$this->assign('typeDate',$typeDate);
		//添加数据
		if(IS_POST)
		{
			// p(Q('post.'));die;
			$this->attrmodel->add_();
			$this->success('添加属性成功');
		}
		$this->display();
	}
	/**
	 * [edit_type 修改类型]
	 * @return [type] [description]
	 */
	public function edit_type()
	{
		if(IS_POST)
		{
			// 获得TYPE的ID
			$typeid = Q('post.typeid');
			//组合WHERE条件
			$where = array('typeid'=>$typeid);
			$this->model->edit_($where);
			$this->success('修改成功',U('index'));


		}

	}
	/**
	 * [del_type 删除类型]
	 * @return [type] [description]
	 */
	public function del_type()
	{
		// 获得GET参数
		$typeid  = Q('get.typeid');
		//获得条件
		$where = array('typeid'=>$typeid);
		//删除
		$this->model->delite_($where);
		// 成功提示
		$this->success('删除成功',U('index'));


	}
	/**
	 * [edit_attr 修改属性]
	 * @return [type] [description]
	 */
	public function edit_attr()
	{
		// 获得ATTR的ID
			$attrid = Q('post.attrid');
			//组合WHERE条件
			$where = array('attrid'=>$attrid);
			$this->attrmodel->edit_($where);
			$this->success('修改成功','');
	}
	/**
	 * [del_type 删除属性]
	 * @return [type] [description]
	 */
	public function del_attr()
	{
		// 获得GET参数
		$attrid  = Q('get.attrid');
		//获得条件
		$where = array('attrid'=>$attrid);
		//删除
		$this->attrmodel->delite_($where);
		// 成功提示
		$this->success('删除成功','');


	}
	/**
	 * [get_all 获得所有数据]
	 * @return [type] [description]
	 */
	public function get_all()
	{
		$this->all();
	}
}

?>
